package com.xuecheng.teaching.agent.hystrix;

import com.xuecheng.api.content.model.dto.CoursePubDTO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.hystrix.BaseAPIHystrix;
import com.xuecheng.common.hystrix.BaseFallbackFactory;
import com.xuecheng.teaching.agent.ContentApiAgent;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.Set;

/**
 * Created on 2021/04/05/19:53 周一
 *
 * @author Lantin
 */

@Component
public class ContentApiAgentFallbackFactory extends BaseFallbackFactory<
        BaseAPIHystrix,
        ContentApiAgentFallbackFactory.ContentApiAgentHystrix,
        ContentApiAgentFallbackFactory.DevContentApiAgentHystrix> {

    /**
     * <p>
     * 生产环境降级方法类
     * </p>
     * 返回
     */
    public static class ContentApiAgentHystrix extends BaseAPIHystrix implements ContentApiAgent {


        public ContentApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }

        @Override
        public RestResponse<Integer> getTeachplanWorkCountById(Long workId) {
            return baseFailResult();
        }

        /**
         * <p>
         * 根据作业id查询绑定了作业的课程名称
         * </p>
         *
         * @param workId 作业id
         * @return RestResponse<List < String>>
         */
        @Override
        public RestResponse<Set<String>> getWorkAssociationPlanName(Long workId) {
            return baseFailResult();
        }

        @Override
        public RestResponse<CoursePubDTO> getCoursePubById(Long coursePubId) {
            return null;
        }
    }

    /**
     * <p>
     * 开发环境降级方法类
     * </p>
     * 返回一个默认值
     */
    public static class DevContentApiAgentHystrix extends BaseAPIHystrix implements ContentApiAgent {

        public DevContentApiAgentHystrix(Throwable throwable) {
            super(throwable);
        }

        @Override
        public RestResponse<Integer> getTeachplanWorkCountById(Long workId) {
            return RestResponse.success(null);
        }

        /**
         * <p>
         * 根据作业id查询绑定了作业的课程名称
         * </p>
         *
         * @param workId 作业id
         * @return RestResponse<List < String>>
         */
        @Override
        public RestResponse<Set<String>> getWorkAssociationPlanName(Long workId) {
            return RestResponse.success(Collections.emptySet());
        }

        @Override
        public RestResponse<CoursePubDTO> getCoursePubById(Long coursePubId) {
            return null;
        }
    }
}
